<?php
/**
 * BaseModel.class.php
 * 基类模型
 * 
 * @author  王中艺 <wangzy_smile@qq.com>
 * @date    2017-08-17
 */

namespace Common\Model;
use Think\Model;

class BaseModel extends Model {

    protected $errMsg   = false;
    
    /**
     * 查询条件前置(基础等值字段转换)
     * @param   $condition
     * @param   $tbName
     * @return  $where
     */
    function setCondition($condition, $tbName){
        $tbName     = $tbName ? $tbName.'.' : '';
        $allows     = $this->getDbFields();
        $where  = [];
        foreach($condition as $key => $val){
            if((!$allows || in_array($key, $allows)) && $val != ''){
                $where[$tbName.$key]    = $val;
            }
        }

        return $where;
    }
    // static function setCondition(&$condition, &$tbName, $allows = false){
    //     $tbName     = $tbName ? $tbName.'.' : '';
    //     $where  = [];
    //     foreach($condition as $key => $val){
    //         if((!$allows || in_array($key, $allows)) && $val != ''){
    //             $where[$tbName.$key]    = $val;
    //         }
    //     }

    //     return $where;
    // }
}
